import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    static class Node {

        public Node() {
        }

        public Node(Integer c_PID, Integer c_UUID, Integer c_NAME, Integer c_STANDARD_TIME) {
            C_PID = c_PID;
            C_UUID = c_UUID;
            C_NAME = c_NAME;
            C_STANDARD_TIME = c_STANDARD_TIME;
        }

        public Integer C_PID;
        public Integer C_UUID;
        public Integer C_NAME;
        public Integer C_STANDARD_TIME;

        public List<Node> nodes;

    }

    public static void main(String[] args) {
        List<Node> list = new ArrayList<>();
        //                  父级id          id                        值
        // list.add(new Node(null, 9001015, 20, 13));
        // list.add(new Node(9001015, 9001020, 2005, 2));
        // list.add(new Node(9001020, 9001025, 200505, 2));
        // list.add(new Node(9001020, 9001030, 200510, 2));
        // list.add(new Node(9001020, 9001035, 200515, 3));
        // list.add(new Node(9001015, 9001040, 2010, 6));
        // list.add(new Node(9001040, 9001045, 201005, 2));
        // list.add(new Node(9001040, 9001050, 201010, 2));
        // list.add(new Node(9001040, 9001055, 201015, 2));

        list.add(new Node(null, 9001000, 10, 8));
        list.add(new Node(9001000, 9001005, 1005, 5));
        list.add(new Node(9001000, 9001010, 1010, 3));
        list.add(new Node(null, 9001015, 20, 10));
        list.add(new Node(9001015, 9001020, 2005, 2));
        list.add(new Node(9001020, 9001025, 200505, 2));
        list.add(new Node(9001020, 9001030, 200510, 2));
        list.add(new Node(9001020, 9001035, 200515, 3));
        list.add(new Node(9001015, 9001040, 2010, 6));
        list.add(new Node(9001040, 9001045, 201005, 2));
        list.add(new Node(9001040, 9001050, 201010, 2));
        list.add(new Node(9001040, 9001055, 201015, 2));

        //顶级节点
        List<Node> topNodes = list.stream().filter(it -> it.C_PID == null).collect(Collectors.toList());
        for (Node target : topNodes) {
            LinkedList<Node> queue = new LinkedList<>();
            //设置起点
            queue.add(target);
            int sum = 0;
            LinkedList<Node> record = new LinkedList<>();
            while (!queue.isEmpty()) {
                //取出头部节点
                Node pop = queue.pop();
                //找到下一级的子节点
                List<Node> collect = list.stream().filter(it -> pop.C_UUID.equals(it.C_PID)).collect(Collectors.toList());

                //如果下一级节点为空，那么就是最底层的节点
                if (collect.size() == 0) {
                    sum += pop.C_STANDARD_TIME;
                    record.add(pop);
                } else {
                    queue.addAll(collect);
                }
            }
            System.out.print("步骤" + target.C_NAME + ":");
            if (target.C_STANDARD_TIME == sum) {
                System.out.println(record.stream().map(it -> "步骤" + it.C_NAME).collect(Collectors.joining("+")));
                //System.out.println(String.join("+", record.stream().map(it -> "值" + it.C_STANDARD_TIME).collect(Collectors.toList())));
            } else {
                System.out.println("不符合条件");
            }
        }
    }
}
